package com.widget.type;

import com.google.common.collect.Lists;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;

/**
 * java类型
 *
 * @author mlliud
 * @date 2020/7/29 10:01 上午
 */
public class ClazzTypeHelper {


  private static void doc() {
    /**
     * 获取对象类型
     */
    List<String> val = Lists.newArrayList("991");
    TypeDescriptor typeDescriptor = TypeDescriptor.forObject(val);

    /**
     * 将数据类型转换为想要类型
     *   contains方法类型匹配，否则值相同类型不同也是false
     *   ps:String->Integer   "val991"->Integer 报错
     */
    TypeDescriptor outDescriptor = TypeDescriptor.collection(HashSet.class, TypeDescriptor.valueOf(Integer.class));
    Set<Integer> convert = (Set) DefaultConversionService.getSharedInstance().convert(val, typeDescriptor, outDescriptor);
  }

  public static void main(String[] args) {
    ClazzTypeHelper.doc();
  }
}
